{{Extend "layout"}}
{{Block "title"}}{{if HasSuffix URL.Path "_add"}}{{"添加二维码"|T}}{{else}}{{"修改二维码"|T}}{{end}}{{/Block}}
{{Block "breadcrumb"}}
{{Super}}
<li><a href="__BACKEND__/official/pay/qrcode_index">{{"二维码管理"|T}}</a></li>
<li class="active">{{if HasSuffix URL.Path "_add"}}{{"添加"|T}}{{else}}{{"修改"|T}}{{end}}</li>
{{/Block}}
{{Block "head"}}
<link rel="stylesheet" type="text/css" href="__ASSETS__/js/selectpage/selectpage.css?t={{BuildTime}}" />
{{/Block}}
{{Block "main"}}
<div class="row">
    <div class="col-md-12">
        <div class="block-flat">
          <div class="header">							
            <h3>{{if HasSuffix URL.Path "_add"}}{{"添加二维码"|T}}{{else}}{{"修改二维码"|T}}{{end}}</h3>
          </div>
          <div class="content">
              <form class="form-horizontal group-border-dashed" parsley-validate novalidate method="POST" action="">
              <div class="form-group">
                <label class="col-sm-2 control-label">{{"选择产品"|T}}</label>
                <div class="col-sm-8">
                  {{$productId := (Formx "productId").Uint64}}
                  <input type="text" name="productId" id="productId" data-init="{{$productId}}" value="{{$productId}}" class="form-control">
                </div>
              </div>
              <div class="form-group">
                  <label class="col-sm-2 control-label">{{"支付方式"|T}}</label>
                  <div class="col-sm-8">
                    {{$v := Form "type"}}
                    <div class="radio radio-primary radio-inline">
                        <input type="radio" value="alipay" name="type" id="type-alipay"{{if or (eq $v "alipay") (eq $v "")}} checked{{end}}> <label for="type-alipay">{{"支付宝"|T}}</label>
                    </div>
                      <div class="radio radio-primary radio-inline">
                        <input type="radio" value="wechat" name="type" id="type-wechat"{{if eq $v "wechat"}} checked{{end}}> <label for="type-wechat">{{"微信"|T}}</label>
                      </div>
                      <div class="radio radio-primary radio-inline">
                        <input type="radio" value="other" name="type" id="type-other"{{if eq $v "other"}} checked{{end}}> <label for="type-other">{{"其它"|T}}</label>
                      </div>
                  </div>
                </div>
              <div class="form-group">
                <label class="col-sm-2 control-label">{{"支付网址"|T}}</label>
                <div class="col-sm-8">
                    <input type="text" id="qrcode-content" class="form-control" name="url" value="{{Form "url"}}">
                </div>
              </div>
              <div class="form-group">
                  <label class="col-sm-2 control-label">{{"付款二维码"|T}}</label>
                  <div class="col-sm-8">
                    <div class="avatar-upload">
                      {{$image := Form "image"}}
                      <img src="{{$image|Default "__ASSETS__/images/user_128.png"}}" class="profile-avatar img-thumbnail" onerror="this.src='__ASSETS__/images/user_128.png';" />
                      <input id="fileupload" type="file" name="files[]">
                      <input type="hidden" id="qrcode-image" name="image" value="{{$image}}" />
                      <div id="progress" class="overlay"></div>
                    </div>
                  </div>
                </div>
              <div class="form-group">
                <label class="col-sm-2 control-label">{{"实付价格"|T}}</label>
                <div class="col-sm-8">
                    <input type="number" class="form-control" name="realPrice" value="{{Form "realPrice"}}" min="0.00">
                </div>
              </div>
              <div class="form-group">
                  <label class="col-sm-2 control-label">{{"状态"|T}}</label>
                  <div class="col-sm-8">
                    {{$v := Form "status"}}
                    <div class="radio radio-primary radio-inline">
                        <input type="radio" value="normal" name="status" id="status-normal"{{if or (eq $v "normal") (eq $v "")}} checked{{end}}> <label for="status-normal">{{"启用"|T}}</label>
                    </div>
                      <div class="radio radio-primary radio-inline">
                        <input type="radio" value="hidden" name="status" id="status-hidden"{{if eq $v "hidden"}} checked{{end}}> <label for="status-hidden">{{"禁用"|T}}</label>
                      </div>
                  </div>
                </div>
              
        <div class="form-group form-submit-group">
					<div class="col-sm-9 col-sm-offset-2">
					  <button type="submit" class="btn btn-primary btn-lg"><i class="fa fa-save"></i> {{"保存"|T}}</button>
					  <button type="reset" class="btn btn-default btn-lg"><i class="fa fa-refresh"></i> {{"重置"|T}}</button>
					</div>
				</div>
            </form>
          </div><!-- /.content -->
        </div><!-- /.block-flat -->
    </div>
</div>
{{/Block}}
{{Block "footer"}}
<script src="__ASSETS__/js/selectpage/selectpage.min.js?t={{BuildTime}}" type="text/javascript"></script>
<script src="__ASSETS__/js/jquery.upload/js/vendor/jquery.ui.widget.js?t={{BuildTime}}"></script>
<script src="__ASSETS__/js/jquery.upload/js/jquery.iframe-transport.js?t={{BuildTime}}"></script>
<script src="__ASSETS__/js/jquery.upload/js/jquery.fileupload.js?t={{BuildTime}}"></script>
<script type="text/javascript">
$(function(){
  $('#productId').selectPage({
    showField : 'name',
    keyField : 'id',
    data : BACKEND_URL+'/official/pay/product_index',
    params : function(){return {};},
    eAjaxSuccess : function(d){
        var result;
        if(d) result = {
          "list":d.Data.listData,
          "pageSize": d.Data.pagination.limit,
          "pageNumber": d.Data.pagination.page,
          "totalRow": d.Data.pagination.rows,
          "totalPage":d.Data.pagination.pages
        };
        else result = undefined;
        return result;
    }
  });
  $('#fileupload').fileupload({
      url: BACKEND_URL+'/manager/upload/qrcode?pipe=deqr',
      dataType: 'json',
      done: function (e, data) {
        var r=data.result;
        if(r.Code!=1){
          return App.message({title:'{{"系统消息"|T}}',text:r.Info,time:5000,sticky:false,class_name:r.Code==1?'success':'error'});
        }
        $.each(r.Data.files, function (index, file) {
            $("#qrcode-image").val(file);
            $('#fileupload').prev('img').attr('src',file);
            $('#progress').fadeOut();
        });
        $('#qrcode-content').val(r.Data.raw);
      },
      progressall: function (e, data) {
          var progress = parseInt(data.loaded / data.total * 100, 10);
          $('#progress').fadeIn();
          $('#progress').css('width',progress + '%');
      }
  }).prop('disabled', !$.support.fileInput).parent().addClass($.support.fileInput ? undefined : 'disabled');
});
</script>
{{/Block}}